<?php
$xtpl = new XTemplate("modules/home/news_task.htm");
//--
$UPLOAD = new UPLOAD();
//--
$POST = $_POST;

if($_POST[type] == 'NEW'){	
	$POST['news_image'] = $UPLOAD->doUploadImage("upload/news/", 'image', '', '150', 'on');	
	$POST['news_date'] =$POST['post_date'];
	$POST['news_title']=($POST['title']);
	$POST['news_content']= ($POST['description']);
	$POST['news_shortdes']= ($POST['news_shortdes']);
	$POST['news_status']=$POST['status'];
	
	//--
	$DB->DBInsert('news', $POST);
	//--
	$GUI->redir("?mod=home&act=news");
}
elseif($_POST[type] == 'EDIT'){
	if($_FILES['image']['name'] !=''){
	 	$POST['news_image'] = $UPLOAD->doUploadImage("upload/news/", 'image', '', '150', 'on');
	}
	
	$POST['news_date'] =$POST['post_date'];
	$POST['news_title']=($POST['title']);
	$POST['news_content']= ($POST['description']);
	$POST['news_shortdes']= ($POST['news_shortdes']);
	$POST['news_status']=$POST['status'];
	//--

	$DB->DBUpdate('news', $POST, "WHERE news_id = '".$POST['id']."'");
	//--
	//-- check image
	if($POST['delete_img'] == '1'){
	// delete_img at root
		$row = $DB->FetchData('news','*',"WHERE news_id='".$_POST[id]."'");	
		@unlink("../upload/news/thumb".$row['news_image']);
	// update
		$sql_up="UPDATE {$DP}news SET news_image='' WHERE news_id =".$_POST[id]."";
		mysql_query($sql_up);
	}
	//-- end
	$GUI->redir("?mod=home&act=news");
}
//--
//--
if($_GET[id] != ''){
	$row = $DB->FetchData('news','*',"WHERE news_id='".$_GET[id]."'");
	$row[type] = 'EDIT';
	$row[title]=stripslashes($row['news_title']);
	$row[id]=$row['news_id'];
	$row[post_date] = $row['news_date'];
	if($row['news_image']!=''){	
		$row['show_image']='<img src="../upload/news/thumb'.$row['news_image'].'" border="0" width="65">';
	}
	//--
	if($row['news_status']=='1'){
 		$row['status']='checked="checked"';
	}else{
		$row['status']='';
	}
		
}else{
	$row[type] = 'NEW';
	$row['news_status']="checked";
	$row['news_date']=date("Y-m-d");
	//--	
}
//--
//--
//--
$_FCKeditor = new FCKeditor("description");
$_FCKeditor->BasePath = $siteFCKeditorPath;
$_FCKeditor->Width = '95%';
$_FCKeditor->Height = '450';
$_FCKeditor->Value = stripslashes($row['news_content']);

//--
$xtpl->assign("write",$row);
//--
//--
$waypathlink = '&raquo;&nbsp;<a href="?mod=home&act=news" class="waypath">News Management</a>:&nbsp;'.$row[type];
$xtpl_main->assign("waypathlink",$waypathlink);
//--
//--
$save_button = $GUI->button_ren("Save","javascript: doSavenews();");
$xtpl->assign("save_button",$save_button);
//--
$cancel_button = $GUI->button_ren("Cancel","javascript: add('?mod=home&act=news');");
$xtpl->assign("cancel_button",$cancel_button);

//$xtpl->parse("center");
//$xtpl->assign("center_file",$xtpl->text("center"));

//--
//--
?>